package gonggong;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

import util.Constant;
import util.TotalClass;

import com.AddressListModule.bean.ContactBean;
import com.AddressListModule.dao.AddressModuleDao;
import com.dati.bean.SendDati;
import com.dati.dao.DatiDao;

public class GetJifen {

	/**
	 * 
	 *@author qingyu zhang
	 *@function:
	 * @param fenshu 此系列的分数
	 * @param totalNum此系列总数
	 * @param rightNum答对的题目数
	 * @return
	 *2011-4-13
	 *下午10:00:43
	 *zzClub
	 *gonggong
	 *String
	 */
	public String getJiFen(String fenshu,int totalNum,int rightNum){
		 int a = rightNum;
		 int b = totalNum;
		 double ab = (double)a/b;
		 BigDecimal bi = new BigDecimal(ab);
		 DecimalFormat df2 = new DecimalFormat("####");
		 String str = df2.format(bi);
		return str;
	}
	/**
	 * 
	 *@author qingyu zhang
	 *@function:把得到 的积分存放到用户表中
	 * @param phone
	 * @param fenshu
	 * @return
	 *2011-4-13
	 *下午10:14:38
	 *zzClub
	 *gonggong
	 *boolean
	 */
	public boolean saveJifenToCustomer(String phone,String fenshu){
		String sql = "";
		boolean bo = false;
		 String condition="customerPhone='"+phone+"'";
		 List<ContactBean>  contactList = new AddressModuleDao().getContactList("tb_kehujifen", "", condition);
		 if(contactList!=null&&contactList.size()>0){
			 int fs = Integer.parseInt(fenshu)+Integer.parseInt(contactList.get(0).getCustomerIntegral());
			 sql="update tb_kehujifen set customerIntegral='"+fs+"',lastTime='"+Constant.decodeDate()+"' where customerPhone='"+phone+"'";
		 }else {
			 int fs = Integer.parseInt(fenshu);
			 sql = "insert into tb_kehujifen (customerPhone,customerIntegral,lastTime) values('"+phone+"',"+fs+",'"+Constant.decodeDate()+"')";
		 }
		 System.out.println("导入积分语句="+sql);
		 bo = new TotalClass().operatorObject(sql);
		 return bo;
	}
	/**
	 * 如果存在答案。修改此记录的状态
	 *@author qingyu zhang
	 *@function:
	 * @param timuId
	 * @param phone
	 * @return
	 *2011-4-14
	 *上午07:54:01
	 *zzClub
	 *gonggong
	 *boolean
	 */
	public boolean modifyDaan(String timuId,String phone){
		boolean bo = false;
		String sql="update tb_daan set state=1 where timuId='"+timuId+"' and phone='"+phone+"' and state=0";
		bo = new TotalClass().operatorObject(sql);
		return bo ;
	}
	/**
	 * 
	 *@author qingyu zhang
	 *@function:根据条件得到此系列中没有发送的题目。
	 * @param seriseId
	 * @param phone
	 * @param endTime
	 * @param state
	 * @param rightOrno
	 * @return
	 *2011-4-14
	 *上午08:08:09
	 *zzClub
	 *gonggong
	 *List<SendDati>
	 */
	public List<SendDati> getSendDati(String seriseId,String phone,String endTime,int state,String rightOrno){
		String condition="";//
		if(rightOrno.equals("")){
			condition="phone='"+phone+"' and seriseId='"+seriseId+"' and endTime='"+endTime+"' and state="+state;
		}else{
			condition="phone='"+phone+"' and seriseId='"+seriseId+"' and endTime='"+endTime+"' and state="+state+" and rightOrno="+rightOrno;
		}
		
		
		
		List<SendDati> sendDatiList = new DatiDao().getSendDati("sendDati", "", condition);
		return sendDatiList;
	}
}
